<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>添加/修改游戏</title>
<%@ include file="/view/common/tags.jsp"%>
</head>
<body>
	<div class="well well_p" >
		<sk:form method="post" cssClass="form-horizontal" action="" id="saveAndUpdateFrom" target="_parent"  enctype="multipart/form-data">
			<div class="form-group">
				<label class="col-xs-3 text-right">游戏:</label>
				<div class="col-xs-4">
					<sk:select cssClass="form-control select" id="gameId" name="gameId" value="${page.wm.ROW_ID}" requiredInit="true" ajaxURL="${userInfoV1}/baseGame/gameSelect?wm[USE_FLAG]=1&wm[DEL_FLAG]=1">
						<option value="">请选择</option>
					</sk:select>
					<input type="hidden" name="gameName" id="gameName" value="">
				</div>
			</div>
			<div class="form-group">
				<label class="col-xs-3 text-right">主类型:</label>
				<div class="col-xs-4">
					<sk:select cssClass="form-control select" name="typeFlag" id="typeFlag" value="" requiredInit="true" ajaxURL="${userInfoV1}/baseType/select?wm[DEL_FLAG]=0&wm[TYPE_FLAG]=30">
                        <option value="">请选择</option>
                    </sk:select>
                    <input type="hidden" name="typeName" id="typeName" value=""/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-xs-3 text-right">商品类型:</label>
				<div class="col-xs-4">
					<input type="text" class="input" name="parentName" id="parentName" value=""  placeholder="请输入商品类型">
				</div>
			</div>
			<div class="form-group">
				<label class="col-xs-3 text-right">排序号:</label>
				<div class="col-xs-7">
					<input type="text" class="input" name="orderByNo" id="orderByNo" value=""  placeholder="请输入排序编号">
				</div>
			</div>
			<div class="form-group" >
				<label class="col-xs-3 text-right">是否开启:</label>
				<div class="col-xs-7">
					<td colspan="2">
	                   	<label for="port"><input id="yse" name="openFlag" type="radio" value="1"/>&nbsp;是</label>&nbsp;&nbsp;&nbsp;&nbsp;
	                   	<label for="no"><input id="no" name="openFlag" type="radio" value="0"/>&nbsp;否</label>
	               	</td>
				</div>
			</div>
			<input type="hidden" id="rowId" name="rowId" value="<%=request.getParameter("rowId")%>">
           	<input type="hidden" id="parentId" name="parentId" value="">
           	<input type="hidden" id="token" name="token" value="">
           	<input type="hidden" id="flag"  value="<%=request.getParameter("flag")%>">
           	<input type="hidden" id="isReCommit" value="0">
		</sk:form>	
	</div>
</body>
<%@ include file="/view/common/footer.jsp"%>
<script type="text/javascript">
$(function(){
    var rowId = $("#rowId").val();
    if(rowId >= 0){
        $.ajax({
            url: "${userInfoV1}/gameGoodsType/getGameGoodsInfo",
            type: "post",
            cache: false,
            data:{"rowId":rowId},
            dataType:"json",
            async:false,
            success: function(data) {
                if (data == null) {
                    return;
                }
                
                $("#gameId").val(data.gameId);
                $("#gameName").val(data.gameName);
                $("#typeFlag").val(data.typeFlag);
                $("#typeName").val(data.typeName);
                $("#orderByNo").val(data.orderByNo);
                $("#parentId").val(data.parentId == undefined ? 0 : data.parentId);
                $("#parentName").val(data.parentName);
                if(data.openFlag == 1){
                    $("#yse").attr("checked","true");
                    $("#no").removeAttr("checked");
                } else {
                    $("#yse").removeAttr("checked");
                    $("#no").attr("checked","true");
                }
            }
        });
    }
	$("#token").val(sessionStorage.getItem("token"));
})

var err = {'1':'添加','2':'修改'};
var action = {'1':'/save','2':'/update'};
function add(){
    var rowId = $('#rowId').val();
    var i;
    if (!CheckUtil.isNotNull(rowId) || rowId == 0) {
        i = 1;//添加
    } else {
        i = 2;//修改
    }
    var gameId = $.trim($("#gameId").val());
    if (!CheckUtil.isNotNull(gameId)) {
        layer.msg("请选择游戏!");
        return;
    }
    $("#gameIdValue").val(gameId);

	var gameName = $("#gameId").find("option:selected").text();
    $("#gameName").val(gameName);

    
    var typeFlag = $("#typeFlag").val();
    if (!CheckUtil.isNotNull(typeFlag)) {
        layer.msg("请选择主类型!");
        return;
    }
    var typeName = $("#typeFlag").find("option:selected").text();
    $("#typeName").val(typeName);


    var parentName = $("#parentName").val();
    if (!CheckUtil.isNotNull(parentName)) {
        layer.msg("商品类型不能为空!");
        return;
    }
    var orderByNo = $('#orderByNo').val();
    if (!CheckUtil.isNotNull(orderByNo)) {
        layer.msg("排序号不能为空!");
        return;
    }
    var openFlag =$('input:radio[name="openFlag"]:checked').val();
    if (!CheckUtil.isNotNull(openFlag)) {
        layer.msg("请选择是否开启!");
        return;
    }
    //loading层
    var index = layer.load(0, {
        shade: [0.1,'#fff'] //0.1透明度的白色背景
    });
    
    $.ajax({
        url: "${userInfoV1}/gameGoodsType" + action[i],
        type: "post",
        cache: false,
        //data:parseJson(decodeURIComponent($("#saveAndUpdateFrom").serialize())),
        data: new FormData($("#saveAndUpdateFrom")[0]),
        dataType:"json",
        processData: false,
        contentType: false,
        async:false,
        success: function(data) {
            layer.close(index);
            if(data.code == 0){
                parent.layer.msg("添加成功！");
            } else if(data.code == 1){
                parent.layer.msg("修改成功！");
            } else if(data.code == "-2"){
                parent.window.location.href="${sysManagerV1}/";
            } else {
                parent.layer.msg(data.message);
            }
            if(data.code >= 0){
                parent.findData();
                parent.layer.close(parent.tableIndex);
            }
        }
    });
    
}

function checkGameName() {
    //渠道游戏ID
    var gameName = $.trim($("#gameName").val());
    $("#gameName").val(gameName);//渠道游戏ID去空格
    var flag = $("#flag").val();
    var rowId = $("#rowId").val();;
    var aa = false;
    if (CheckUtil.isNotNull(gameName)) {
        $.ajax({
            type: "post",
            cache: false,
            url: "${userInfoV1}/baseGame/checkGameIsExist",
            data:{gameName:gameName, gameId:rowId},
            dataType:"json",
            async:false,
            success: function(data) {
                aa = data;
            }
        });
    }
    return aa;  
}
</script>
</html>